package tech.popsoft.cip.message.client.framework.handler;

import tech.popsoft.cip.message.common.entity.MessageException;
import tech.popsoft.cip.message.client.manage.entity.ApiMessageTopic;
import tech.popsoft.cip.message.client.manage.service.ApiMessageLogService;
import tech.popsoft.cip.message.client.manage.service.ApiMessageTopicService;
import tech.popsoft.platform.common.enums.StatusEnum;
import tech.popsoft.platform.common.utils.SpringUtil;

/**
 * 消息处理抽象类
 *
 * @author wqliu
 * @date 2021-10-13 9:07
 **/
public  class MessageHandler {


    protected ApiMessageLogService apiMessageLogService = SpringUtil.getBean(ApiMessageLogService.class);

    protected ApiMessageTopicService apiMessageTopicService=SpringUtil.getBean(ApiMessageTopicService.class);



    /**
     * 验证主题编码
     *
     * @param topicCode 主题编码
     */
    protected void validateTopic(String topicCode) {
        try {

            ApiMessageTopic messageTopic = apiMessageTopicService.getByCode(topicCode);
            if(messageTopic.getStatus().equals(StatusEnum.DEAD.name())){
                throw new MessageException("S102", "消息主题不可用");
            }
        }catch (Exception ex){
            throw new MessageException("S101", "消息主题不存在");
        }

    }


}
